SETLOCAL ENABLEDELAYEDEXPANSION

SET CURRENTDIR=%CD%

SET BISONPATH=D:\Tools\win_flex_bison-latest
SET FLEXPATH=D:\Tools\win_flex_bison-latest
SET CMAKEPATH=D:\Tools\CMake 2.8\bin
SET SDKDIR=C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin

SET SCRIPTPATH=%~dp0
SET BASEDIR=!SCRIPTPATH:~0,-1!

SET BUILDDIR=!BASEDIR!\build

SET PATH=%BISONPATH%;%FLEXPATH%;%CMAKEPATH%;%SDKDIR%;%PATH%
CALL setenv.cmd /release
IF NOT %ERRORLEVEL% == 0 GOTO END

IF EXIST !BUILDDIR! RMDIR /S /Q !BUILDDIR!
IF NOT %ERRORLEVEL% == 0 GOTO END

MKDIR !BUILDDIR!
IF NOT %ERRORLEVEL% == 0 GOTO END

cd !BUILDDIR!
IF NOT %ERRORLEVEL% == 0 GOTO END

cmake -G "NMake Makefiles" ..
IF NOT %ERRORLEVEL% == 0 GOTO END

nmake
IF NOT %ERRORLEVEL% == 0 GOTO END

nmake package
IF NOT %ERRORLEVEL% == 0 GOTO END

:END
cd !CURRENTDIR!